package readlastthreeline;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Print last n lines from a file:
 * 
 * Example:
 * 
 * logs.log content: 1 2 3 4 5
 * 
 * cmd> java Tail logs.log 3 3 4 5
 */
public class TestReader {

	public static void main(String[] args) throws IOException {
		File f = new File("log.txt");
		Scanner s = null;
		try {

			s = new Scanner(f);
			Integer nmbr = 0;
			ArrayList<String> fileContent = new ArrayList<String>();
			while (s.hasNext()) {

				fileContent.add(s.next());
				nmbr += 1;

			}
			for (int i = fileContent.size() - 3; i < fileContent.size(); i++) {

				System.out.println(fileContent.get(i));
			}

			// System.out.println(nmbr);

		} catch (FileNotFoundException e) {
		
			e.printStackTrace();
		} finally {

			s.close();
		}

	}

}
